#include <memcache.h>
#include <iostream>
#include <vector>
#include <string>
#include "mcache.h"
#include "/data/home/neolin/3part_build/mcache/src/crc32_table.h"

using namespace std;
using namespace mcache;

static u_int32_t
t_hkey_fun(const string &str1) {
//#ifdef USE_CRC32_HASH
	  const char *key=str1.c_str();
		u_int32_t crc;
		  size_t len=strlen(key);
			size_t i;

			 crc = ~0;
					for (i = 0; i < len; i++)
							crc = (crc >> 8) ^ crc32tab[(crc ^ (key[i])) & 0xff];

					  crc = (~crc >> 16) & 0x7fff;

						return crc == 0 ? 1 : crc;
}

int testMap()
{
	char buff[200];
	map<int,int> gmap;
    for( int i=0; i<10000; i++ )
	{
        sprintf(buff,"1Q.userapp.%s_%u","score",i+10001);
        gmap[t_hkey_fun(buff)%2]++;
	    // cout << t_hkey_fun(buff) << endl;
	}
	
cout <<"0 :" <<  gmap[0] <<endl;
cout <<"1 :" <<  gmap[1] << endl;
//  #define MCM_CALLBACK_KEY    md5783365dee46035fa36d8d9e6fe15da0f

   //  cout << t_hkey_fun((const char*)MCM_CALLBACK_KEY) << endl;
}

int main(int argc, char** argv)
{

//	return testMap();

	Cache cache;
	cache.addServer("172.16.195.31:11211");
	cache.addServer("172.16.195.31:11311");

	cout <<"number servers.is " <<  cache.tca()->num_servers << endl;
	vector<string> keys;

	map<string, string> results;


	if (argc > 1)
	{
		string strkey = argv[1];
		keys.push_back(strkey);
		results.clear();
		cache.multi_get(keys, results);

		for(map<string, string>::iterator i=results.begin(); i!=results.end(); i++)
	    {
	        cout << i->first << ": " << i->second << endl;
	    }
	}
}
